package com.atguigu.chapter05.Transform;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.ConnectedStreams;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.co.CoMapFunction;

/**
 * TODO
 *
 * @author cjp
 * @version 1.0
 * @date 2021/3/3 15:29
 */
public class Flink08_Union {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        DataStreamSource<Integer> numDS = env.fromElements(1, 2, 3, 4, 5);
        DataStreamSource<Integer> numDS1 = env.fromElements(11, 12, 13, 14, 15);
        DataStreamSource<Integer> numDS2 = env.fromElements(111, 112, 113, 114, 115);

        // TODO Transform - 合流 Union
        DataStream<Integer> unionDS = numDS.union(numDS1).union(numDS2);

        SingleOutputStreamOperator<String> resultDS = unionDS.map(new MapFunction<Integer, String>() {
            @Override
            public String map(Integer value) throws Exception {
                return "我是:" + value;
            }
        });

        resultDS.print();

        env.execute();
    }
}

/*
    Union:
        1) 流的数据类型必须要一致
        2）可以同时 union 多条流
 */